package com.kgc.controller;

import com.kgc.pojo.User;
import com.kgc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String selectUserLogin(String userName, String password, HttpSession session, Model model){
        User user=userService.selectUserLogin(userName,password);
        if (user==null){
            model.addAttribute("error","账号或密码输入错误！");
            return "forward:/jsp/index.jsp";
        }
        session.setAttribute("user",user);
        return "redirect:/jsp/main.jsp";
    }

    @RequestMapping("/logout")
    public String userLogout(HttpSession session){
        session.removeAttribute("user");
        return "redirect:/jsp/index.jsp";
    }
}
